package com.lanou.beautifulwardrobe.activity;


import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.TabHost;

import com.lanou.beautifulwardrobe.R;
import com.lanou.beautifulwardrobe.Activity_zhuti.ActivityFragment;
import com.lanou.beautifulwardrobe.Brand.BrandFragment;
import com.lanou.beautifulwardrobe.Home.HomeFragment;
import com.lanou.beautifulwardrobe.Space.SpaceFragment;


public class MainActivity extends FragmentActivity {
    private TabHost mHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        replaceFragment();
    }

    private void initView() {
        mHost = (TabHost) findViewById(android.R.id.tabhost);
        mHost.setup();
        TabHost.TabSpec homeSpec = mHost.newTabSpec("homeSpec");
        homeSpec.setIndicator(getLayoutInflater().inflate(R.layout.maintab_home, null));
        homeSpec.setContent(R.id.homeFrameLayout);

        TabHost.TabSpec brandSpec = mHost.newTabSpec("brandSpec");
        brandSpec.setIndicator(getLayoutInflater().inflate(R.layout.maintab_brand, null));
        brandSpec.setContent(R.id.brandFrameLayout);

        TabHost.TabSpec activitySpec = mHost.newTabSpec("activitySpec");
        activitySpec.setIndicator(getLayoutInflater().inflate(R.layout.maintab_activity, null));
        activitySpec.setContent(R.id.activityFrameLayout);

        TabHost.TabSpec cartSpec = mHost.newTabSpec("cartSpec");
        cartSpec.setIndicator(getLayoutInflater().inflate(R.layout.maintab_cart, null));
        cartSpec.setContent(R.id.cartFrameLayout);

        TabHost.TabSpec spaceSpec = mHost.newTabSpec("spaceSpec");
        spaceSpec.setIndicator(getLayoutInflater().inflate(R.layout.maintab_space, null));
        spaceSpec.setContent(R.id.spaceFrameLayout);

        mHost.addTab(homeSpec);
        mHost.addTab(brandSpec);
        mHost.addTab(activitySpec);
        mHost.addTab(cartSpec);
        mHost.addTab(spaceSpec);
        mHost.setCurrentTab(0);

    }

    private void replaceFragment() {

        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.homeFrameLayout, HomeFragment.getHomeFragment());
        ft.replace(R.id.brandFrameLayout, new BrandFragment());
        ft.replace(R.id.activityFrameLayout, ActivityFragment.getInstance());
        ft.replace(R.id.spaceFrameLayout, SpaceFragment.getspaceFragment());
        ft.commit();
    }
}
